package com.wecheir.utils;

import com.alibaba.fastjson.JSON;

import java.io.Serializable;

public class ResponseUtils {

    //请求成功2xx
    //请求成功并且返回有数据
    public final static Integer CODE_SUCCESS = 200;
    //请求成功但是返回数据为空
    public final static Integer CODE_SUCCESS_NODATA = 201;

    //请求失败4xx
    //请求失败
    public final static Integer CODE_FAILURE = 400;



    //返回状态码
    Integer code = null;

    //返回信息
    String message = null;

    //返回数据(Json格式)
    Object  data = null;


    public static ResponseUtils  setSuccess(Object data){
        ResponseUtils responseUtils = new ResponseUtils();
        responseUtils.setCode(CODE_SUCCESS);
        responseUtils.setData(data);
//        return JSON.toJSONString(responseUtils);
        return responseUtils;
    }

    public static ResponseUtils setFailure(String message){
        ResponseUtils responseUtils = new ResponseUtils();
        responseUtils.setCode(CODE_FAILURE);
        responseUtils.setMessage(message);
//        return JSON.toJSONString(responseUtils);
        return responseUtils;
    }

    public static ResponseUtils setAny(Integer code,Object data,String message){
        ResponseUtils responseUtils = new ResponseUtils();
        responseUtils.setCode(code);
        responseUtils.setData(data);
        responseUtils.setMessage(message);
//        return JSON.toJSONString(responseUtils);
        return responseUtils;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object  data) {
        this.data = data;
    }


    @Override
    public String toString() {
        return "ResponseUtils{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data='" + data + '\'' +
                '}';
    }
}
